package com.fengye.algorithms.leecode;

import java.util.*;

/**
 * @Author fengye
 * @Date 2023/5/9 10:51
 **/
public class ShuffleAnArray384 {
    public static void main(String[] args) {
        Solution solution = new Solution(new int[]{1,2,3});
        Arrays.stream(solution.shuffle()).forEach(System.out::println);
        Arrays.stream(solution.reset()).forEach(System.err::println);
        Arrays.stream(solution.shuffle()).forEach(System.out::println);
        Arrays.stream(solution.reset()).forEach(System.err::println);
        Arrays.stream(solution.shuffle()).forEach(System.out::println);
    }
}

class Solution {
    int[] original;
    int[] shuffles;

    public Solution(int[] nums) {
        original = nums;
        shuffles = new int[nums.length];
    }

    public int[] reset() {
        return original;
    }

    public int[] shuffle() {
        List<Integer> temp = new ArrayList<>();
        for (int i : original) {
            temp.add(i);
        }
        Random random = new Random();
        for(int i=0;i < original.length; i++) {
            int r = random.nextInt(temp.size());
            shuffles[i] = temp.remove(r);
        }
        return shuffles;
    }
}

/**
 * Your Solution object will be instantiated and called as such:
 * Solution obj = new Solution(nums);
 * int[] param_1 = obj.reset();
 * int[] param_2 = obj.shuffle();
 */
